#链接数据库增删改查
import requests

# 定义四个方法，对应要测试的四个接口
class IhrmEmpCurd(object):
    # 添加员工接口
    @classmethod
    def add_emp(cls,header, body):
        url = "http://ihrm-test.itheima.net/api/sys/user"
        resp_add = requests.post(url=url, headers=header, json=body)
        return resp_add

        # {"Content-Type": "application/json", "Authorization": "Bearer 3a754ba7-cf5c-4f64-8d9b-1c5ee6ad5de3"}
        # {"username": "alex05", "mobile": "13012312315", "workNumber": "1234"}

    # 查询员工接口
    @classmethod
    def query_emp(cls, header,url):
        # url = "http://ihrm-test.itheima.net/api/sys/user/1539077369204080640"
        resp_select = requests.get(url=url, headers=header)
        return resp_select

        # {"Authorization": "Bearer 3a754ba7-cf5c-4f64-8d9b-1c5ee6ad5de3"}

    # 修改员工接口
    @classmethod
    def modify_emp(cls,header,body):
        url = "http://ihrm-test.itheima.net/api/sys/user/1539077369204080640"
        resp_modify = requests.put(url=url, headers=header, json=body)
        return resp_modify

        # {"Content-Type": "application /json", "Authorization": "Bearer 3a754ba7-cf5c-4f64-8d9b-1c5ee6ad5de3"}
        # {"username": "alex"}

    # 删除员工接口
    @classmethod
    def delete_emp(cls, header):
        url = "http://ihrm-test.itheima.net/api/sys/user/1539077369204080640"
        resp_del = requests.delete(url=url, headers=header)
        return  resp_del

        # {"Authorization": "Bearer 3a754ba7-cf5c-4f64-8d9b-1c5ee6ad5de3"}

if __name__ == '__main__':
    hader1 = {"Content-Type": "application/json", "Authorization": "Bearer 3a754ba7-cf5c-4f64-8d9b-1c5ee6ad5de3"}
    body1 =  {"username": "alex05", "mobile": "13012312315", "workNumber": "1234"}
    resp1 = IhrmEmpCurd.add_emp(hader1,body1)
    print("添加员工：",resp1.json())

    hader2 = {"Authorization": "Bearer 3a754ba7-cf5c-4f64-8d9b-1c5ee6ad5de3"}
    resp2 = IhrmEmpCurd.query_emp(hader2)
    print("查询员工：",resp2.json())

    hader3 = {"Content-Type": "application/json", "Authorization": "Bearer 3a754ba7-cf5c-4f64-8d9b-1c5ee6ad5de3"}
    body3 =  {"username": "alex"}
    resp3 = IhrmEmpCurd.modify_emp(hader3,body3)
    print("修改员工：",resp3.json())

    hader4 = {"Authorization": "Bearer 3a754ba7-cf5c-4f64-8d9b-1c5ee6ad5de3"}
    resp4 = IhrmEmpCurd.query_emp(hader4)
    print("删除员工：",resp4.json())